import {
  controller,
  httpGet as GetMapping,
  httpPost as PostMapping,
} from "inversify-express-utils";
import { PostService } from "./service";
import { inject } from "inversify";
import type { Request, Response } from "express";

@controller("/post") //路由前缀
export class Post {
  constructor(@inject(PostService) private readonly PostService: PostService) {}

  @GetMapping("/index") //接口
  public async getIndex(req: Request, res: Response) {
    console.log("req: ", req.query);
    let result = await this.PostService.getList();
    res.send(result);
  }

  @PostMapping("/create")
  public async createPost(req: Request, res: Response) {
    console.log("req: ", req.body);
    let result = await this.PostService.createPost(req.body);
    res.send(result);
  }
}
